<?php

namespace app\api\controller;

use think\Controller;
use think\Request;

class Cases extends controller
{
    public function getCasesList(Request $request)
    {
        $page = $request->get('page', 1, 'intval');
        $page = $page > 0 ? $page : 1;
        $list = Db('case')
            ->field('case_id,title,image,company,description')
            ->order('sort asc')
            ->page($page, 10)
            ->select();
        return ['code' => 0, 'data' => $list];
    }

    public function getCasesInfo(Request $request)
    {
        $case_id = $request->get('case_id', 0, 'intval');
        $info = Db('case')
            ->where('case_id', $case_id)
            ->find();
        if (!$info) {
            return ['code' => 2, 'msg' => '案例已删除'];
        }
        return ['code' => 0, 'data' => $info];
    }
}
